package com.okami.web.customer;

import com.okami.domain.customer.BankCard;
import com.okami.domain.customer.User;
import com.okami.domain.customer.UserRepository;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.OneToMany;
import java.util.Date;
import java.util.Set;

/**
 * @author: TanJingyu
 * @create: 2020-12-19 11:28
 **/
@RestController
@RequestMapping("/customer")
public class UserController {
    @Autowired
    private UserRepository userRepository;

    @GetMapping("/{userId}")
    public UserVO getUser(@PathVariable Long userId) {
        return userRepository.findById(userId).map(u -> {
            UserVO userVO = new UserVO();
            BeanUtils.copyProperties(u, userVO);
            return userVO;
        }).orElse(new UserVO());
    }

    @Data
    public static class UserVO {
        private Long id;
        private String userName;
        private Integer age;
        private Date createdTime;
    }
}
